package com.cms.server.resolver.plugins;

import java.sql.ResultSet;

import com.efounder.builder.base.data.DataSetUtils;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.eai.data.JParamObject;
import com.efounder.form.EFFormDataModel;
import com.efounder.form.io.FormDataResolverAdapter;
import com.efounder.sql.JStatement;
import com.persistence.FLOW_TASK_LIST;

public class CMSCanRetakePSHTForm extends FormDataResolverAdapter {

	//初始化FormDataModel
	public void prepareSaveForm(JStatement stmt, EFFormDataModel model, JParamObject PO) throws Exception {		
		String                            strSql = "";
		EFDataSet                     flowNodeDS = null;
		EFRowSet                      nodeRowset = EFRowSet.getInstance();
		ResultSet                             rs = null;
		
		//获取流程节点
		strSql = "select * from FLOW_NODE_LIST where exists(SELECT 1 FROM FLOW_USER_LIST where FLOW_USER_LIST.FLOW_BH = FLOW_NODE_LIST.FLOW_ID and ((FLOW_USER_LIST.FLOW_BM = '" 
			   + PO.GetValueByParamName(FLOW_TASK_LIST._OP_BMBH, "") + "' and FLOW_USER_LIST.F_TYPE = 'BM')or (FLOW_USER_LIST.FLOW_USER = '" + PO.GetValueByParamName(FLOW_TASK_LIST._OP_USER, "") + "'" 
			   + " and FLOW_USER_LIST.FLOW_BM = '" + PO.GetValueByParamName(FLOW_TASK_LIST._OP_BMBH, "") + "' and FLOW_USER_LIST.F_TYPE = 'USER'))"
			   + " and FLOW_USER_LIST.NODE_BH = FLOW_NODE_LIST.NODE_ID) and FLOW_NODE_LIST.NODE_ID = '" + PO.GetValueByParamName(FLOW_TASK_LIST._OP_NODE, "") + "'"
			   + " and FLOW_NODE_LIST.FLOW_ID = 'PSHT_EDIT_FLOW'"
			   + " order by  NODE_ID";
		rs = stmt.executeQuery(strSql);
		flowNodeDS = DataSetUtils.resultSet2DataSet(rs, flowNodeDS);
		nodeRowset = flowNodeDS.getRowSet(0);
		
		if(nodeRowset == null) {
			throw new Exception("提交失败！原因：<br>【" + PO.GetValueByParamName(FLOW_TASK_LIST._OP_USER, "") + "-" + PO.GetValueByParamName(FLOW_TASK_LIST._OP_USER_NAME, "") + "】没有权限提交单据！");
		}
	}
}
